import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../../resource/language/generated/l10n.dart';
import '../../interface/root_proxy_model.dart';
import 'doufeng_privilege_desc_page_model.dart';

class DoufengPrivilegeDescPage extends StatelessWidget {
  var hasPrivilege = false;
  // CarMetaInfo? carMetaInfo;

  /// 特权类型
  Widget get type => Container(
        decoration: BoxDecoration(
          color: const Color(0xFF1F1C22),
          borderRadius: BorderRadius.circular(20),
        ),
        padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 13),
        margin: const EdgeInsets.only(right: 6),
        child: const Text(
          'privilegeType',
          style: TextStyle(
            fontSize: 13,
            fontWeight: FontWeight.w500,
            color: Colors.white,
          ),
        ),
      );

  /// 特权描述
  Widget get desc {
    return RichText(
      text: TextSpan(children: [
        WidgetSpan(
          child: type,
          alignment: PlaceholderAlignment.middle,
        ),
        const TextSpan(
          text: 'privilegeDesc',
          style: TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.w500,
            color: Color(0xff333333),
          ),
        )
      ]),
      softWrap: true,
    );
  }

  /// 特权详细描述
  Widget get extDesc {
    return hasPrivilege
        ? const Text(
            'privilegeExtDesc',
            style: TextStyle(
              fontSize: 12,
              fontWeight: FontWeight.w400,
              color: Color(0xff333333),
            ),
            softWrap: true,
          )
        : Text(
            T.current!.this_car_no_privilege,
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w500,
              color: Color(0xff666666),
            ),
          );
  }

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: [
          ChangeNotifierProxyProvider<RootProxyModel,
              DoufengPrivilegeDescPageModel>(
            create: (context) => DoufengPrivilegeDescPageModel(),
            update: (context, rootProxyModel, leafModel) {
              if (leafModel == null) throw ArgumentError.notNull('leafModel');
              leafModel.roomModel = rootProxyModel;
              return leafModel;
            },
          ),
        ],
        child: Consumer<DoufengPrivilegeDescPageModel>(
            builder: (context, model, child) {
          // carMetaInfo = model.roomModel.channel!.carInfo;
          // hasPrivilege = carMetaInfo == null
          //     ? false
          //     : CarUtils.hasPrivilege(carMetaInfo?.privilegeType);
          return Container(
            decoration: const BoxDecoration(
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(16), topRight: Radius.circular(16)),
              image: DecorationImage(
                image: AssetImage("assets/images/bg_doufeng_privilege.png"),
                fit: BoxFit.cover,
              ),
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Image.asset(
                  "assets/images/ic_doufeng_privilege_top.png",
                  width: 182,
                  height: 32,
                  fit: BoxFit.contain,
                ),
                const SizedBox(
                  height: 20,
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 24),
                  child: Text(
                    T.current!.car_privilege_intro,
                    style: TextStyle(
                      fontSize: 12,
                      fontWeight: FontWeight.w400,
                      color: Color(0xFFFEF9EC),
                    ),
                  ),
                ),
                const SizedBox(
                  height: 20,
                ),
                Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(16),
                    gradient: const LinearGradient(
                      colors: [Color(0xFFFEFEFE), Color(0xFFFFF5EB)],
                    ),
                  ),
                  width: double.infinity,
                  margin: const EdgeInsets.symmetric(horizontal: 12),
                  padding: const EdgeInsets.all(12),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        T.current!.this_car_privilege,
                        style: TextStyle(
                          fontSize: 15,
                          fontWeight: FontWeight.w500,
                          color: Colors.black,
                        ),
                      ),
                      const SizedBox(
                        height: 12,
                      ),
                      if (hasPrivilege) ...[
                        desc,
                        const SizedBox(
                          height: 8,
                        ),
                      ],
                      extDesc,
                    ],
                  ),
                ),
                const SizedBox(
                  height: 21,
                ),
                // if (model.roomModel.meWithSlot != null &&
                //     model.roomModel.meWithSlot!.micType ==
                //         MicTypeEnum.CAR_OWNER_MIC)
                SafeArea(
                  child: CupertinoButton(
                    onPressed: () {
                      // if (hasPrivilege) {
                      //   Reporter.track(TrackEvent.ridePrivilege, {
                      //     "rid": model.roomModel.channel!.channelId.toInt(),
                      //     "step": "start",
                      //   });
                      // }

                      model.confirm(context, hasPrivilege).then(
                        (value) {
                          // if (model.roomModel.channel!.owner
                          //     .hasTmpCarMetaInfo()) {
                          //   // BlindBoxMainPage.show(refer: "ride_experience");
                          // } else {
                          //   if (value) {
                          //     // model.showPrivilegeUserDialog(context);
                          //   } else {
                          //     // BlindBoxMainPage.show(refer: "room");
                          //   }
                          // }
                        },
                      );
                    },
                    minSize: 0,
                    padding: const EdgeInsets.only(bottom: 20),
                    child: const Text(
                        'model.roomModel.channel!.owner.hasTmpCarMetaInfo'),
                    // child: model.roomModel.channel!.owner.hasTmpCarMetaInfo()
                    //     ? Column(
                    //         children: [
                    //           Text(
                    //             T.current!.own_car_can_use_privilege,
                    //             style: TextStyle(fontSize: 12),
                    //           ),
                    //           const SizedBox(
                    //             height: 8,
                    //           ),
                    //           Container(
                    //             margin:
                    //                 const EdgeInsets.symmetric(horizontal: 48),
                    //             width: double.infinity,
                    //             height: 52,
                    //             alignment: Alignment.center,
                    //             decoration: BoxDecoration(
                    //               borderRadius: BorderRadius.circular(26),
                    //               gradient: const LinearGradient(colors: [
                    //                 Color(0xFFEFC9A5),
                    //                 Color(0xFFF7E2C4)
                    //               ]),
                    //               // color: Color(0xffffd400)
                    //             ),
                    //             child: Text(
                    //               T.current.get_car,
                    //               style: const TextStyle(
                    //                 fontSize: 16,
                    //                 fontWeight: FontWeight.w500,
                    //                 color: Color(0xff333333),
                    //               ),
                    //             ),
                    //           )
                    //         ],
                    //       )
                    //     : Container(
                    //         margin: const EdgeInsets.symmetric(horizontal: 48),
                    //         width: double.infinity,
                    //         height: 52,
                    //         alignment: Alignment.center,
                    //         decoration: BoxDecoration(
                    //           borderRadius: BorderRadius.circular(26),
                    //           gradient: const LinearGradient(colors: [
                    //             Color(0xFFEFC9A5),
                    //             Color(0xFFF7E2C4)
                    //           ]),
                    //           // color: Color(0xffffd400)
                    //         ),
                    //         child: Text(
                    //           hasPrivilege
                    //               ? T.current!.use_now
                    //               : T.current!.upgrade_car,
                    //           style: const TextStyle(
                    //             fontSize: 16,
                    //             fontWeight: FontWeight.w500,
                    //             color: Color(0xff333333),
                    //           ),
                    //         ),
                    //       ),
                  ),
                )
              ],
            ),
          );
        }));
  }
}
